using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;
using OpenComposite.Base.Designer;

namespace OpenComposite.EII.Designer.SCA
{
	public class StandaloneReferenceSymbol : Symbol
	{
		#region Initialization
		public StandaloneReferenceSymbol()
		{
			init();
		}
		private void init()
		{
			this.BeginUpdate();

			_startConnector = null;

			this.Border = BorderType.Rectangle;
			this.BorderColor = Color.Black;
			this.BorderWidth = 2;

			this.BackColor = Color.YellowGreen;

			//this.Name = "standaloneReferenceSymbol" + GetCount(typeof(StandaloneReferenceSymbol));
			this.Text = "Standalone Reference";
			this.TextAlign = ContentAlignment.MiddleCenter;

			this.Size = new Size(100, 40);
			this.MinimumSize = new Size(70, 40);

			this.NameTextBox.AutoSize = false;
			this.NameTextBox.Bounds = this.ClientRectangle;

			//
			// this.ContextMenuStrip
			//
			this.ContextMenuStrip = new ContextMenuStrip();
			this.ContextMenuStrip.Items.Add("Remove Standalone Reference", null, new EventHandler(context_Remove));

			this.EndUpdate();
		}
		#endregion

		#region Public Members

		#region Properties
		#endregion

		#region Events
		#endregion

		#region Methods
		#endregion

		#region Overrides
		public override object GetDragObject(Point location, MouseButtons button)
		{
			return this;
		}
		public override void DropObject(object obj, Point location, MouseButtons button)
		{
		}
		public override bool IsDropAllowed(object obj, Point location, MouseButtons button)
		{
			return false;
		}
		public override bool CreateRouteStart(DesignerControl controlEnd, out IConnector connector,
			out LineCap cap, out CustomLineCap customcap, out RouteDockDirection dockStart,
			out RouteDockDirection dockEnd, out bool useStartConnectorAsRouteStart)
		{
			bool ok = base.CreateRouteStart(controlEnd, out connector, out cap, out customcap, out dockStart, out dockEnd, out useStartConnectorAsRouteStart);

			if ( _startConnector == null ) {
				_startConnector = new ReferenceConnectorSymbol();
				_startConnector.Location = new Point(this.Width - (int)( _startConnector.Width / 2 ) - 5, (int)( this.ClientRectangle.Height / 2 ) - ( _startConnector.Height / 2 ));
				_startConnector.Anchor = System.Windows.Forms.AnchorStyles.Right;
				this.Controls.Add(_startConnector);
			}

			connector = _startConnector;
			cap = LineCap.RoundAnchor;
			customcap = null;

			return ok;
		}
		public override bool CreateRouteEnd(DesignerControl controlStart, out IConnector connector,
			out LineCap cap, out CustomLineCap customcap, out RouteDockDirection dockStart,
			out RouteDockDirection dockEnd, out bool useEndConnectorAsRouteEnd)
		{
			bool ok = base.CreateRouteEnd(controlStart, out connector, out cap, out customcap, out dockStart, out dockEnd, out useEndConnectorAsRouteEnd);

			cap = LineCap.NoAnchor;
			customcap = null;

			return ok;
		}
		#endregion

		#endregion

		#region Private Members

		#region Variables
		private ReferenceConnectorSymbol _startConnector;
		#endregion

		#region Methods
		#endregion

		#region Event Handlers
		private void context_Remove(object sender, EventArgs e)
		{
			this.Remove();
		}
		#endregion

		#endregion
	}
}
